<?php
session_start();
header('P3P: CP="CAO PSA OUR"');
require_once ("utils/config.php");
require_once ("utils/redirect.php");

$auth_url = "http://www.facebook.com/dialog/oauth?scope=email,read_stream,offline_access,manage_pages&client_id=" . APP_ID . "&redirect_uri=" . urlencode(CANVAS_PAGE) . "&response_type=token";

  
$signed_request = $_REQUEST["signed_request"];

list($encoded_sig, $payload) = explode('.', $signed_request, 2);

$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

$_SESSION['facebook_id'] = $data["user_id"]; // Store the facebookID for use later

if(empty($data["user_id"]))
	redirect($auth_url);
else
	redirect("../test/testList.php");
?>
